{include file="../public/header.html"}
<!-- 内容主体区域 -->
<style>
    .layui-table-view .layui-table{
        width: 100%!important;
    }
</style>
<div style="padding: 0 15px;">
    <div class="layui-card" style="line-height: 50px;">
        {$breadcrum}
    </div>
    <div class="layui-row">
        <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
            <ul class="layui-tab-title">
                <li class="layui-this"><a href="/Invite/index/{$compid}">企业邀请{if $num>0}<span class="layui-badge-dot" style="transform: translateY(-50%)"></span>{/if}</a></li>
                {if $adminer!=3}<li><a href="/Company/index/{$compid}">入驻审核{if $totals>0}<span class="layui-badge-dot" style="transform: translateY(-50%)"></span>{/if}</a></li>{/if}
            </ul>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
            <form class='layui-form' style="display: flex;justify-content: flex-end;">
                <div class="layui-form-item" style="margin-bottom: 0;">

                    <div class="layui-inline" style="margin: 0;">
                        <select name="status">
                            <option value="">请选择</option>
                            <option value="0" selected="true">待处理</option>
                            <option value="1">已同意</option>
                            <option value="2">已拒绝</option>
                        </select>
                    </div>
                    <div class="layui-inline" style="margin: 0;">
                        <input type="text" name="title" id="tableTitle" placeholder="请输入企业名称" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-btn" lay-submit lay-filter="formDemo">搜索</div>
                </div>
            </form>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
            <table class="layui-hide" id="demo" lay-filter="test"></table>
        </div>
    </div>

    <script>

        $("#inviBtn").click(function () {
            //console.log('111')
            var url = '/Invite/Invite/'+{$compid};
            var params = {};
            $.ajax({
                url:url,
                data: params,
                type: 'POST',
                dataType: 'json',
                success:function (res) {
                    if(res.status == '0'){
                        layui.use(['layer','form'],function () {
                            var layer = layui.layer,
                                form = layui.form;

                            layer.open({
                                type: 1,
                                area:['500px', '200px'],
                                title: "生成邀请链接",
                                shadeClose: true,
                                content:$('#inviBox'),
                                success:function(layer0,index0){
                                    $("#inviTitle").val(res.url);
                                    $("#copyBtn").click(function () {
                                        var url = $("#inviTitle");
                                        url.select();
                                        document.execCommand("Copy"); // 执行浏览器复制命令
                                        layer.msg("复制成功！");
                                        layer.close(index0);
                                    });
                                }
                            })
                        })
                    }
                }
            })
        });
        


        layui.use(['form','table'],function () {
            var form = layui.form,
                table = layui.table;
            var url = '/Invite/AccountInvite/'+{$compid};





            table.render({
                elem: '#demo',
                url: url,
                method:'post',
                where: { name: '',status: '0' },
                title: '邀请数据表',
                cols: [
                    [
                        //{ field: 'rows', title: '序号', width: '5%', align: 'center' },
                        { field: 'invname', title: '邀请人姓名', width: '10%',align: 'center' },
                        { field: 'compname', title: '邀请企业', width: '20%',align: 'center' },
                        { field: 'bmmc', title: '邀请部门', width: '15%',align: 'center' },
                        { field: 'ctime', title: '邀请时间', width: '20%',align: 'center' },
                        { field: 'status', title: '状态', width: '10%',align: 'center',templet:function (d){
                                var status = d.status;
                                if(status == 0){
                                    return '<div>待处理</div>'
                                }else if(status == 1){
                                    return '<div>已同意</div>'
                                }else if(status == 2){
                                    return '<div>已拒绝</div>'
                                }
                            } },
                        { field: 'status', title: '操作', width: '20%', align:'center', templet:function (d){
                                var status = d.status;
                                if(status == 0){
                                    return '<a class="layui-btn layui-btn-sm" lay-event="yes">同意邀请</a>'+ '<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="no">拒绝邀请</a>'
                                }else if(status == 1) {
                                    return '<a class="layui-btn layui-btn-disabled layui-btn-sm" style="background-color:#e6e6e6;">同意邀请</a>' + '<a class="layui-btn layui-btn-disabled layui-btn-sm" style="background-color:#e6e6e6;">拒绝邀请</a>'
                                }else if(status == 2) {
                                    return '<a class="layui-btn layui-btn-disabled layui-btn-sm" style="background-color:#e6e6e6;">同意邀请</a>' + '<a class="layui-btn layui-btn-disabled layui-btn-sm" style="background-color:#e6e6e6;">拒绝邀请</a>'
                                }
                            }  }
                    ]
                ],
                page: true,
                limits: [3,5,10],
                limit: 15,
                id: 'testReload',
                parseData: function(res){
                    //console.log(res);
                    var result;
                    if(this.page.curr){
                        result = res.data.data.slice(this.limit*(this.page.curr-1),this.limit*this.page.curr);
                    }
                    else{
                        result = res.data.data.slice(0,this.limit);
                    }
                    return{
                        "code": res.data.status, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.totals, //解析数据长度
                        "data": result //解析数据列表
                    }
                }
            });



            // 监听行工具事件
            table.on('tool(test)',function (obj) {
                var layEvent = obj.event;

                if(layEvent === 'yes'){
                    var url = '/Invite/PassInvite/' + obj.data.id;
                    var params = {};
                    $.ajax({
                        url:url,
                        data: params,
                        type: 'POST',
                        dataType: 'json',
                        success:function (res) {
                            if(res.status == '0'){
                                layer.msg(res.msg,function () {
                                    var url = '/Invite/AccountInvite/'+{$compid};
                                    var params = {
                                        name: '',
                                        status: '0'
                                    };
                                    $.ajax({
                                        url:url,
                                        data: params,
                                        type: 'POST',
                                        dataType: 'json',
                                        success:function (res) {
                                            if(res.data.totals == '0'){
                                                parent.document.location.reload();
                                            }else {
                                                window.location.reload();
                                            }
                                        }
                                    })
                                })
                            }else if(res.status == '110'){
                                layer.msg(res.msg)
                            }
                        }
                    })
                }else if(layEvent === 'no'){
                    var url = '/Invite/RejectedInvite/' + obj.data.id
                    var params = {};
                    $.ajax({
                        url:url,
                        data: params,
                        type: 'POST',
                        dataType: 'json',
                        success:function (res) {
                            //console.log(url);
                            if(res.status == '0'){
                                layer.msg(res.msg,function () {
                                    var url = '/Invite/AccountInvite/'+{$compid};
                                    var params = {
                                        name: '',
                                        status: '0'
                                    };
                                    $.ajax({
                                        url:url,
                                        data: params,
                                        type: 'POST',
                                        dataType: 'json',
                                        success:function (res) {
                                            if(res.data.totals == '0'){
                                                parent.document.location.reload();
                                            }else {
                                                window.location.reload();
                                            }
                                        }
                                    })
                                })
                            }else if(res.status == '110'){
                                layer.msg(res.msg)
                            }
                        }
                    })
                }
            });

            //监听提交
            form.on('submit(formDemo)', function(data){
                // layer.msg(JSON.stringify(data.field));

                table.reload('testReload',{
                    url: url,
                    method:'post',
                    where: { name: data.field.title,status: data.field.status },
                    title: '邀请数据表',
                });
                return false;
            });


            $(document).ready(function() {
                // select下拉框选中触发事件
                form.on("select", function(data){
                    var name = $("#tableTitle").val();
                    table.reload('testReload',{
                        url: url,
                        method:'post',
                        where: { name: name,status: data.value },
                        title: '审核数据表',
                    });
                });

            });



        })
    </script>
</div>
{include file="../public/foot.html"}